var app=new Vue({
    el:"#app",
    data:{
        list:[
            {
                id:1,
                name:'桃子',
                price:8.99,
                count:1
            },
            {
                id:2,
                name:'苹果',
                price:9.99,
                count:1
            },
            {
                id:3,
                name:'雪梨',
                price:7.99,
                count:1
            },
            {
                id:4,
                name:'香蕉',
                price:5.99,
                count:1
            },
            {
                id:5,
                name:'葡萄',
                price:7.99,
                count:1
            }


        ]
    },
    computed:{
        totalPrice:function(){
            var total=0;
            for(var i=0;i<this.list.length;i++){
                var item=this.list[i];
                total +=item.price*item.count;
            }
            return total.toString().replace(/\B(?=(\d{3})+$)/g,',');
            
        }
    },
    methods:{
        handleReduce:function(index){
            if(this.list[index].count===1) return;
            this.list[index].count--;
        },
        handleAdd:function(index){
            this.list[index].count++;
        },
        handleRemove:function(index){
            this.list.splice(index,1);
        }

    }
});